package com.googlecode.afx.view.binding;

import java.util.HashMap;
import java.util.Map;

import javafx.scene.Node;

import com.googlecode.afx.view.NodeHandler;
import com.googlecode.afx.view.NodeWrapper;

/**
 * Node-handler that extracts all values from fields that support databinding.
 * 
 * @author Martin
 *
 */
public class ValueExtractingNodeHandler implements NodeHandler {

	private Map<String, Object> allValues = new HashMap<String, Object>();
	
	public ValueExtractingNodeHandler() {
	}
	
	@Override
	public void process(Node node) {
		if(NodeWrapper.supportsPrimaryValue(node.getClass())) {
			NodeWrapper wrapper = new NodeWrapper(node);
			this.allValues.put(node.getId(), wrapper.getPrimaryValue());
		}
	}

	public Map<String, Object> getAllValues() {
		return allValues;
	}

}
